﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using Emoney.DataAccess;
using LiuYan.Base;


namespace LiuYan.Service
{
    public class LoginService
    {
        /// <summary>
        /// 管理员登录后台管理系统
        /// </summary>
        /// <param name="userName"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public DataTable Login(string userName, string password)
        {
         SqlParameter[] parameters = new SqlParameter[]
         {
             new SqlParameter("@username",SqlDbType.VarChar,50),
             new SqlParameter("@password",SqlDbType.VarChar,50),
         };
            parameters[0].Value = userName;
            parameters[1].Value = new MD5().Md5Get32(password).ToLower();
            string sql = "select top(1) * from TB_Admin where password=@password and userName=@username";
            return SqlHelper.ExecuteDataset(Connection.conStr, CommandType.Text, sql, parameters).Tables[0];
        }




        /// <summary>
        /// 修改密码
        /// </summary>
        /// <param name="pwd"></param>
        /// <param name="pwd1"></param>
        /// <returns></returns>
        public int EditPwd(string pwd, string pwd1,int userId)
        {
            SqlParameter[] parameters = new SqlParameter[]
         {
             new SqlParameter("@pwd",SqlDbType.VarChar,50),
             new SqlParameter("@pwd1",SqlDbType.VarChar,50),
         };
            parameters[0].Value = new MD5().Md5Get32(pwd).ToLower();
            parameters[1].Value = new MD5().Md5Get32(pwd1).ToLower();
            string sql = "update TB_Admin set password=@pwd1 where password=@pwd and id=" + userId;
            return SqlHelper.ExecuteNonQuery(Connection.conStr, CommandType.Text, sql, parameters);
        }
      




    }
}
